
import 'package:flutter/material.dart';
import 'package:flutter_test_demo/dialog/dialog_bean.dart';

import 'base_dialog.dart';

class DialogUtil {

  /*
   *  显示 公用的对话框
   *  backPress：点击返回，true消失，false不消失
   *  cancelOutside： 点击框外区域，true消失， false不消失
   */
  static _reqDialog(BuildContext context, BaseDialog dialog, {bool? backPress, bool? cancelOutside}){
    showDialog<Null>(
        context: context,
        barrierDismissible: cancelOutside ?? false,
        builder: (BuildContext context) {
          dialog.setContext(context);
          return WillPopScope(
            child: dialog,
            onWillPop: () async {
              return Future.value(backPress ?? true);
            },
          );
        }
    ).then((value) => {//对话框关闭后

    });
  }

  /// 授权对话框
  static perDialog(BuildContext context){
    _reqDialog(context, BaseDialog(DialogBean(
      title: '权限申请',
      content: '已禁用权限，请手动授予',
      confirmText: '去设置',
      showCancel: false,
    )));
  }
}